package com.yzr.common.stream;

import java.util.stream.LongStream;

/**
 * Stream 并行
 */
public class StreamDemo {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        long first = LongStream.range(0L, 10_0000_0000L).parallel().reduce(0L, Long::sum);
        long end = System.currentTimeMillis();
        System.out.println("时间=" + (end - start));
        System.out.println(first);

        Long num = 0L;
        long start2 = System.currentTimeMillis();
        for (Long i = 0L; i < 10_0000_0000L; i++) {
            num += i;
        }
        long end2 = System.currentTimeMillis();
        System.out.println("时间=" + (end2 - start2));
        System.out.println(num);


    }
}
